namespace BM.Tools.Xml.Schema
{
    using System.Collections.Generic;
    using System.Linq;
    using System.Xml.Schema;

    public class SchemaProber
    {
        private SchemaSetHelper schemaSetHelper;

        /// <summary>
        /// Initializes a new instance of the <see cref="SchemaProber"/> class.
        /// </summary>
        /// <param name="schemaSet">
        /// The schema set.
        /// </param>
        public SchemaProber(XmlSchemaSet schemaSet)
        {
            SchemaSet = schemaSet;
        }

        /// <summary>
        /// Gets SchemaSet.
        /// </summary>
        public XmlSchemaSet SchemaSet
        {
            get;
            private set;            
        }

        /// <summary>
        /// Gets SchemaSetHelper.
        /// </summary>
        public SchemaSetHelper SchemaSetHelper
        {
            get
            {
                if (schemaSetHelper == null)
                {
                    schemaSetHelper = new SchemaSetHelper(SchemaSet);
                }

                return schemaSetHelper;
            }
        }

        public IEnumerable<string> GetRootNames()
        {
            return SchemaSetHelper.MainSchema.Items.OfType<XmlSchemaElement>().Select(schemaElement => schemaElement.Name);
        }
    }
}